<?php
/**
 * 话题----热门话题旁边的----分类
 * 【2019-01-26】已加缓存
 */
require_once dirname(dirname(__DIR__)) . "/common.php";

use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\UserMaterial;

// 缓存
$cacheKeyList = REDIS_PREFIX . "topic_fenlie" . rand(1, 5);
$cacheTime = rand(30, 50);
$redis = SysResource::getRedis();

$resData = $redis->get($cacheKeyList);
if (!empty($resData)) {
    $resData = json_decode($resData, true);
    Response::output(0, "查询成功", $resData);
} else {
    //实例化数据库
    $db = SysResource::getDB(false);
    $UserMaterial = new UserMaterial($db);
    $da1 = $UserMaterial->dub_fenlie();
    if (!empty($da1)) {
        foreach ($da1 as $k => $v) {
            $re = $UserMaterial->ones("user_material", "id", ['examine' => 3, "mix_status" => 1, "del1" => 2, "join_type" => $v['id']]);
            if (empty($re)) {
                unset($da1[$k]);
            }
        }
        $da2 = [];
        foreach ($da1 as $kk => $vv) {
            $da2[] = $vv;
        }
        $redis->set($cacheKeyList,json_encode($da2),$cacheTime);
        Response::output(0, "查询成功", $da2);
    } else {
        Response::output(0, "查询成功", []);
    }
}


